package com.shg.admin;

import com.shg.admin.bean.City;
import com.shg.admin.service.CityService;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;

import java.util.Random;

@Slf4j
@SpringBootApplication
@MapperScan(value = "com.shg.admin.mapper")
@ServletComponentScan(basePackages = {"com.shg.admin"})
public class Boot05WebAdminMyApplication implements CommandLineRunner{

    private final CityService cityService;

    public Boot05WebAdminMyApplication(CityService cityService) {
        this.cityService = cityService;
    }


    public static void main(String[] args) {
        SpringApplication.run(Boot05WebAdminMyApplication.class, args);
    }


    @Override
    public void run(String... args) throws Exception {
        Random random = new Random();
        int randomNumber = random.nextInt(201);
        City city = new City();
        city.setCity("深圳"+randomNumber);
        city.setProvince("广东"+randomNumber);
        city.setCountry("中国"+randomNumber);
        cityService.insertCity(city);
        log.info("{}",city);
    }
}
